﻿namespace CoreWebApiNuGet.ApiContracts
{
    public class ApiResults
    {
        #region 同步(请求成功)

        /// <summary>
        /// Author：Geek Dog  Content：普通请求成功 AddTime：2022-3-23 14:37:43  
        /// </summary>
        /// <param name="ResultMsgs">返回提示语</param>
        /// <param name="Model">返回参数</param>
        /// <param name="ResultCount">总条数(列表使用)</param>
        /// <returns></returns>
        public static BaseResultMsg ReturnSuccess(object Model = null, string ResultMsgs = null, int ResultCount = 0)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 200;
            msg.ResultType = "success";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            msg.ResultCount = ResultCount;
            return msg;
        }

        /// <summary>
        /// Author：Geek Dog  Content：普通请求成功(带语言版本) AddTime：2019-1-8 14:25:30  
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="Model">返回参数</param>
        /// <returns></returns>
        public static BaseResultMsg ReturnSuccessLanguage( object Model = null, string ResultMsgs = null, int ResultCount = 0)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 200;
            msg.ResultType = "success";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            msg.ResultCount = ResultCount;
            return msg;
        }

        #endregion

        #region 异步(请求成功)

        /// <summary>
        /// Author：Geek Dog  Content：普通请求成功 AddTime：2022-3-23 14:37:43  
        /// </summary>
        /// <param name="ResultCode">返回Code</param>
        /// <param name="ResultMsgs">返回提示语</param>
        /// <param name="Model">返回参数</param>
        /// <param name="ResultCount">总条数(列表使用)</param>
        /// <returns></returns>
        public static Task<BaseResultMsg> ReturnSuccessAsync(object Model = null, string ResultMsgs = null, int ResultCount = 0)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 200;
            msg.ResultType = "success";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            msg.ResultCount = ResultCount;
            return Task.FromResult(msg);
        }

        /// <summary>
        /// Author：Geek Dog  Content：普通请求成功(带语言版本) AddTime：2019-1-8 14:25:30  
        /// </summary>
        /// <param name="enumType">枚举类型</param>
        /// <param name="Model">返回参数</param>
        /// <returns></returns>
        public static Task<BaseResultMsg> ReturnSuccessLanguageAsync(object Model = null, string ResultMsgs = null, int ResultCount = 0)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 200;
            msg.ResultType = "success";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            msg.ResultCount = ResultCount;
            return Task.FromResult(msg);
        }

        #endregion

        #region 同步(请求失败)

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败 AddTime：2019-1-8 14:29:48  
        /// </summary>
        /// <param name="ResultCode">错误代码</param>
        /// <param name="ResultMsgs">提示信息</param>
        /// <param name="Model">返回参数</param>
        /// <returns></returns>
        public static BaseResultMsg ReturnError( string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 400;
            msg.ResultType = "error";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            return msg;
        }

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败(带语言版本) AddTime：2022-3-23 14:40:31  
        /// </summary>
        /// <param name="ResultCode"></param>
        /// <param name="ResultMsgs"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static BaseResultMsg ReturnErrorLanguage(string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 400;
            msg.ResultType = "error";
            msg.ResultMsgs =  ResultMsgs;
            msg.ResultData = Model;
            return msg;
        }

        #endregion

        #region 异步(请求失败)

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败 AddTime：2019-1-8 14:29:48  
        /// </summary>
        /// <param name="ResultCode">错误代码</param>
        /// <param name="ResultMsgs">提示信息</param>
        /// <param name="Model">返回参数</param>
        /// <returns></returns>
        public static Task<BaseResultMsg> ReturnErrorAsync( string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 400;
            msg.ResultType = "error";
            msg.ResultMsgs =  ResultMsgs;
            msg.ResultData = Model;
            return Task.FromResult(msg);
        }

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败(带语言版本) AddTime：2022-3-23 14:40:31  
        /// </summary>
        /// <param name="ResultCode"></param>
        /// <param name="ResultMsgs"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static Task<BaseResultMsg> ReturnErrorLanguageAsync(string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 400;
            msg.ResultType = "error";
            msg.ResultMsgs =ResultMsgs;
            msg.ResultData = Model;
            return Task.FromResult(msg);
        }

        #endregion

        #region 同步(请求异常,警告提示)

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败警告提示 AddTime：2022-3-23 14:45:04  
        /// </summary>
        /// <param name="ResultMsgs"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static BaseResultMsg ReturnWarning( string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 401;
            msg.ResultType = "warning";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            return msg;
        }

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败警告提示(带语言版本) AddTime：2019-9-19 16:52:39  
        /// </summary>
        /// <param name="ResultMsgs"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static BaseResultMsg ReturnWarningLanguage(string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 401;
            msg.ResultType = "warning";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            return msg;
        }

        #endregion

        #region 异步(请求异常,警告提示)

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败警告提示 AddTime：2022-3-23 14:45:04  
        /// </summary>
        /// <param name="ResultMsgs"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static Task<BaseResultMsg> ReturnWarningAsync(string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 401;
            msg.ResultType = "warning";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            return Task.FromResult(msg);
        }

        /// <summary>
        /// Author：Geek Dog  Content：普通请求失败警告提示(带语言版本) AddTime：2019-9-19 16:52:39  
        /// </summary>
        /// <param name="ResultMsgs"></param>
        /// <param name="Model"></param>
        /// <returns></returns>
        public static Task<BaseResultMsg> ReturnWarningLanguageAsync( string ResultMsgs = null, dynamic Model = null)
        {
            BaseResultMsg msg = new BaseResultMsg();
            msg.ResultCode = 401;
            msg.ResultType = "warning";
            msg.ResultMsgs = ResultMsgs;
            msg.ResultData = Model;
            return Task.FromResult(msg);
        }

        #endregion

        /// <summary>
        /// 基础返回参
        /// </summary>
        public class BaseResultMsg
        {
            /// <summary>
            /// 状态码
            /// </summary>
            public object ResultCode { get; set; }
            /// <summary>
            /// 获取 消息内容
            /// </summary>
            public string ResultMsgs { get; set; } = string.Empty;
            /// <summary>
            /// 获取 消息类型
            /// </summary>
            public string ResultType { get; set; }
            /// <summary>
            /// 获取 返回数据
            /// </summary>
            public object ResultData { get; set; } = new { };

            /// <summary>
            /// 总行数
            /// </summary>
            public int ResultCount { get; set; }
        }
    }
}
